//联盟卡类型 0 高端卡  1 中端卡
var type = globalFun.GetQueryString("id"),
  shareMsg = {};
shareMsg.url = location.href;
var Gg0 = false,
  Gg1 = false,
  clubcardType, clubcardId, cardId, limitTime, ggstr = ':',
  ggstr1;
//联盟卡详情
Auth();
$.ajax({
  type: "post",
  url: apicom + "mobile/view/clubcard/getclubcardmsg",
  data: {
    cardtype: type
  },
  success: function(res) {
    if (typeof res == "string") {
      var data = JSON.parse(res);
    } else {
      var data = res;
    }
    if (data.code == 1) {
      var data = data.content;
      var lunbo = '';
      //联盟卡头部信息
      var cardMsg = data.clubCard;
      //分享信息
      shareMsg.title = cardMsg.cardName;
      shareMsg.content = cardMsg.description;
      shareMsg.imgUrl = cardMsg.attachmentList[0].address;
      shareMsg.type = 1;
      $.each(cardMsg.attachmentList, function(index, val) {
        lunbo += '<div><a href="javascript:;"><img class="img-responsive" src="' + val.address + '"/></a></div>';
      })
      $('.swipe-wrap').html(lunbo);
      $('.swipe-wrap1').html(lunbo);
      $('#lunbo-zs').html(cardMsg.attachmentList.length);
      //小播图初始化
      var elem = document.getElementById('mySwipe');
      window.mySwipe = Swipe(elem, {
        //4s一次轮播
        effect: 4000,
        type: 'bullets',
        disableScroll: false,
        callback: function(index, element) {
          $("#position li").eq(index).addClass("active").siblings().removeClass("active");
          $('#current-in').html(index + 1)
          console.log(index)
          var changeImg = $(element).find("img").attr("src");
          $(".shop_smallpic img").attr("src", changeImg);
        }
      });
      $("#position li").click(
        function() {
          mySwipe.slide($(this).index());
        });


      //大轮播图初始化
      var elem = document.getElementById('mySwipe1');
      window.mySwipe = Swipe(elem, {
        //4s一次轮播
        effect: 4000,
        type: 'bullets',
        disableScroll: false,
        callback: function(index, element) {
          $("#position li").eq(index).addClass("active").siblings().removeClass("active");
          $('#current-in').html(index + 1)
          console.log(index)
        }
      });
      $("#position li").click(
        function() {
          mySwipe.slide($(this).index());
        });

      $(".shop_smallpic img").attr("src", cardMsg.attachmentList[0].address);
      if(cardMsg.minPrice == cardMsg.maxPrice){
      	$(".head-maney").html('¥<span class="zong">' + cardMsg.minPrice + '</span>');
      }else{
      	$(".head-maney").html('¥<span class="zong">' + cardMsg.minPrice + '</span>' + '-¥<span class="zong">' + cardMsg.maxPrice + '</span>');
      }
      
      $(".shop_cotent").html(cardMsg.description);
      $('.head-mc').html(cardMsg.cardName);
    }
    if (data.code == 0) {
      tips(data.msg);
    }
  },
  error: function(err) {
    tips("服务器错误!");
  }
});

//获取最新评论信息
$.ajax({
  type: "post",
  url: apicom + "mobile/view/clubcard/getClubCardCommentList",
  data: {
    level: 1,
    cardtype: type,
    page: 1,
    rows: 10
  },
  success: function(res) {
    if (typeof res == "string") {
      var data = JSON.parse(res);
    } else {
      var data = res;
    }
    if (data.code == 1) {
      $(".sppj-zsl").html(data.content.sumStart);
      $(".hp").html(data.content.goodStart);
      $(".zp").html(data.content.middleStart);
      $(".cp").html(data.content.lakStart);
      if (data.content.orderCommentList.length == 0) {
        $(".pingjia_content").html("");
      } else {
        var orderMsg = data.content.orderCommentList[0];
        var titleContent = '';
        titleContent += '<span><img src="' + orderMsg.logAddress + '" alt="" /></span>' + orderMsg.nickname;
        $(".pdescript").html(orderMsg.createdTime + '&nbsp;&nbsp;规格：' + orderMsg.clubType);
        $(".pcontent").html(orderMsg.content);

        $(".phead").html(titleContent);
      }

    }
  },
  error: function(err) {
    tips("服务器错误");
  }
});



$("#guiG").click(function() {
  $('.mengban').show();
  $('.box').show();
});
$('.sppj-4').click(function() {
  var src = $("#mySwipe .swipe-wrap div:first-child img").attr("src")
  var type1 = $(this).attr("type");
  shareMsg = JSON.stringify(shareMsg);
  localStorage.setItem('share_url',shareMsg)
  window.location.href = "../homektxq/klm-pjxq.html?id=" + type + "&type=" + type1;
});
$(".sppj-z p").click(function() {
  var type1 = $(this).attr("type");
    shareMsg = JSON.stringify(shareMsg);
  localStorage.setItem('share_url',shareMsg)
  window.location.href = "../homektxq/klm-pjxq.html?id=" + type + "&type=" + type1;
});
$(".waimian").scroll(function() {
  //	if($(this).scrollTop() == 0){
  //		$(".shop_smallpic").hide();
  //	}else{
  //		$(".shop_smallpic").show();
  //	}
});


$('.boxb-list1').on('click', 'span', function() {
  ggstr = ggstr1;
  if ($("#type2").hasClass("bianred")) {
    if ($(this).hasClass('bianred')) {
      Gg1 = false;
      $(this).removeClass('bianred')
      ggstr = ggstr1;
    } else {
      Gg1 = true;
      clubcardId = $(this).text();
      ggstr += $(this).text();
      cardId = $(this).attr("cardId");
      limitTime = $(this).attr("limitTime");
      $(".maney-a").html($(this).attr("price"));
      $(".box-pic img").attr("src", $(this).attr("imgUrl"));
      $(this).addClass('bianred').siblings().removeClass('bianred')
    }
  }
})

$('.boxb-list2').on('click', 'span', function() {
  ggstr = ggstr1;
  if ($("#type1").hasClass("bianred")) {
    if ($(this).hasClass('bianred')) {
      Gg1 = false;
      $(this).removeClass('bianred')
      ggstr = ggstr1;
    } else {
      Gg1 = true;
      clubcardId = $(this).text();
      ggstr += $(this).text();
      cardId = $(this).attr("cardId");
      limitTime = $(this).attr("limitTime");
      $(".maney-a").html($(this).attr("price"));
      $(".box-pic img").attr("src", $(this).attr("imgUrl"));
      $(this).addClass('bianred').siblings().removeClass('bianred')
    }
  }
})

$('.boxb-list0').on('click', 'span', function() {
  ggstr = ":";
  if ($(this).hasClass('bianred')) {
    $(this).removeClass('bianred');
    Gg0 = false;
    Gg1 = false;
    $('.boxb-list1 span').removeClass("bianred");
    $('.boxb-list2 span').removeClass("bianred");
  } else {
    Gg0 = true;
    Gg1 = false;
    if ($(this).text() == "周期卡") {
      clubcardType = 0;
    } else {
      clubcardType = 1;
    }
    ggstr += $(this).text() + '/';
    ggstr1 = ggstr;
    $(this).addClass('bianred').siblings().removeClass('bianred');
    $('.boxb-list1 span').removeClass("bianred");
    $('.boxb-list2 span').removeClass("bianred");
  }
})


//卡联盟规格
$.ajax({
  type: "post",
  url: apicom + "mobile/view/clubcard/getclubcardtype",
  data: {
    cardtype1: (type * 1 + 1),
    cardtype2: 1
  },
  success: function(res) {
    if (typeof res == "string") {
      var data = JSON.parse(res);
    } else {
      var data = res;
    }
    var zqContent = '';
    if (data.code == 1) {
      $.each(data.content, function(index, val) {
        zqContent += '<span limitTime="' + val.beginTime + '至' + val.endTime + '" cardId="' + val.id + '" imgUrl="' + val.imageAddress + '" price="' + val.price + '">' + val.num + '个月</span>';
      });
      if (data.content.length == 0) {} else {
        $(".boxb-list0").append('<span id="type1">周期卡</span>');
      }
    }
    $(".boxb-list2").html(zqContent);
  },
  error: function(err) {
    tips("服务器错误!");
  }

});

//卡联盟规格
$.ajax({
  type: "post",
  url: apicom + "mobile/view/clubcard/getclubcardtype",
  data: {
    cardtype1: (type * 1 + 1),
    cardtype2: 2
  },
  success: function(res) {
    if (typeof res == "string") {
      var data = JSON.parse(res);
    } else {
      var data = res;
    }
    var csContent = '';
    if (data.code == 1) {
      $.each(data.content, function(index, val) {
        csContent += '<span limitTime="' + val.beginTime + '至' + val.endTime + '" cardId="' + val.id + '" imgUrl="' + val.imageAddress + '" price="' + val.price + '">' + val.num + '次</span>';
      });
      if (data.content.length == 0) {} else {
        $(".boxb-list0").append('<span id="type2">次数卡</span>');
      }
    }
    $(".boxb-list1").html(csContent);
  },
  error: function(err) {
    tips("服务器错误!");
  }

});



//确定购买
$('.btn').click(function() {
  if (!Auth()) {
    toClientLogin();
  } else {
    var price = $(".maney-a").text() * $(".num").html();
    if (Gg0 && Gg1) {
      var xdMsg = {
        type: type,
        clubcardType: clubcardType,
        clubcardId: clubcardId,
        price: price,
        cardId: cardId,
        id: user_info.id,
        time: limitTime
      };
      sessionStorage.setItem("xdMsg", JSON.stringify(xdMsg));
      location.href = "../lianmengcard-order/lianmnegcard-order.html";
    } else {
      tips("请选择规格");
    }
  }

})



//加减商品
//$(".jia").click(function(event) {
//  // $(".caozuo input").val(1);
//  if($(".num").html()==""){
//      $(".num").html(1)
//  }
//  var num=$(".num").html()*1+1;
//  $(".num").html(num);
//});

//$(".jian").click(function(event) {
//  if($(".num").html()==""){
//      $(".num").html(1)
//  }
//  var num=$(".num").html()*1-1;
//  $(".num").html(num)
//  if($(".num").html()<0 || $(".num").html()==0){
//      $(".num").html(1)
//  }
//});



// 点击收回 收回
$('.box-right').click(function() {
  //		$('.boxb-list span').removeClass('bianred');
  $('.mengban').hide();
  $('.box').hide();
  if (Gg0 && Gg1) {
    $(".GG").html(ggstr);
    //			ggstr=":";
    //			Gg0=false;
    //			Gg1=false;
  } else {
    $(".GG").html(ggstr);
  }
})
$(document).on("click",".swipe-wrap div",function(){
	$('.liehome').addClass("bigLb");
});

// 点击放小
$('.liehome').on('click', function() {
  $(this).removeClass("bigLb");
})

// 点击购物车 显示
$('.gwc').click(function() {
  $('.mengban').show();
  $('.box').show();
  if ($(".btn").hasClass("goBuy")) {
    $(".btn").removeClass("goBuy");
  }
})



$('.nav1-img').click(function() {
  window.history.go(-1);
})



// 点击立即购买 跳转到填写订单


$(".buy").click(function() {
  if (!Auth()) {
    toClientLogin();
  } else {
    $('.mengban').show();
    $('.box').show();
    $('.btn').addClass("goBuy");
  }
})


//分享
$(".navFx-img").click(function() {
  if (mark == 1) {
    setupWebViewJavascriptBridge(function(bridge) {
      bridge.callHandler("jsToClientShare", shareMsg, function(data, responseCallback) {});
    });
  } else if (mark == 0) {
    var shareData = JSON.stringify(shareMsg);
    window.stub.jsToClientShare(shareData);
  }
});